package com.cjm.one.goods.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.goods.service.GoodsCommentService;
import com.cjm.one.model.goods.entity.GoodsComment;
import com.cjm.one.model.goods.vo.GoodsCommentVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Tag(name = "商品评论管理")
@RequestMapping("/admin/goods/comment")
public class GoodsCommentController
{
    @Resource
    private GoodsCommentService goodsCommentService;

    @GetMapping("list")
    @Operation(summary = "查询商品评论列表")
    public Result<Page<GoodsComment>> list(@RequestParam(name = "current") Long current,
                                           @RequestParam(name = "size") Long size,
                                           @RequestParam(name = "text",required = false) String text,
                                           @RequestParam(name = "userId", required = false) Long userId,
                                           @RequestParam(name = "goodsId", required = false) Long goodsId)
    {
        return Result.ok(goodsCommentService.findList(current, size,userId, text, goodsId));
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据id查询商品评论")
    public Result<GoodsCommentVo> get(@PathVariable(name = "id") Long id)
        {
        return Result.ok(goodsCommentService.getCommentById(id));
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "根据id删除商品评论")
    public Result<Boolean> delete(@PathVariable(name = "id") Long id){
        return Result.ok(goodsCommentService.removeById(id));
    }
}
